package src.java.easy;

public class Solution27 {
    public static int removeElement(int[] nums, int val) {
        int length = nums.length;
        int left = 0, right = length - 1;
        int k = 0;
        while (left < right) {
            if (nums[left] == val) {
                nums[left] = nums[right];
                right--;
                k++;
            } else {
                left++;
            }
        }
        return length - k;
    }

    public static void main(String[] args) {
        int[] nums = {0,1,2,2,3,0,4,2};
        removeElement(nums, 2);
    }
}
